package proj.unions.general;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

public abstract class Template_Activity extends Activity{
	
	protected Activity mActivity = null;
	
	protected String SYSTEM_REASON = "reason";
	protected String SYSTEM_HOME_KEY = "homekey";
	protected String SYSTEM_HOME_KEY_LONG = "recentapps";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		SuperTools.getInstance().setCurActivity(this);//保存当前窗口
		SuperTools.getInstance().setScreenOrientationLandscape(this);//设置锁定横屏
		mActivity = this;
		//注册广播  
        registerReceiver(mHomeKeyEventReceiver, new IntentFilter(  
                Intent.ACTION_CLOSE_SYSTEM_DIALOGS));  
        
		super.onCreate(savedInstanceState);
	}
	
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();

	}
	
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();

	}
	
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		
	}
	
	protected abstract void onReceiveHomeKeyEvent(String reason);
	
	/**
	 * 监听是否点击了home键将客户端推到后台
	 */
	private BroadcastReceiver mHomeKeyEventReceiver = new BroadcastReceiver() {
		
		@Override
		public void onReceive(Context context, Intent intent) {
			String action = intent.getAction();
			if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) 
			{
				String reason = intent.getStringExtra(SYSTEM_REASON);
				onReceiveHomeKeyEvent(reason);
			} 
		}
	};
	
}
